First, your application needs to create or attach to an instance of the browser that uses HttpWatch, as explained in the Ruby - Overview. Having done this, your application will contain references to Controller and Plugin objects.
The following discussion assumes that these object references are called control and extension, respectively.
Before starting recording, you should decide whether to enable or disable HttpWatch filtering. The automation interface only allows you to enable or disable an existing filter. The filtering criteria itself can only be set up manually through the HttpWatch extension user interface.
If you do not want specifically to use a filter it is best to disable filtering in your application, as follows:
Turn Off Filtering |
Copy Code
|
---|---|
plugin.Log.EnableFilter(false) |
Alternatively to enable filtering, make the same call, but with the parameter set to true.
To make sure that you don't pick up traffic that was previously recorded in HttpWatch by user or another automation program you should clear the Log object that is associate with the Plugin. This can be done with the Plugin object's Clear method:
Clear the HttpWatch Log |
Copy Code
|
---|---|
plugin.Clear() |
It may also be necessary to put the browser into a known state at the start of your test. Often this is achieved by clearing the browser cache and cookie database to emulate the state of the browser when a new visitor opens a web page. The extension object provides two methods, ClearCache and ClearAllCookies to perform these tasks.
To activate traffic logging call the Plugin object's Record method:
Start Recording |
Copy Code
|
---|---|
plugin.Record() |
Of course, nothing will be recorded by HttpWatch until the browser starts to access and interact with web pages.
In an automation program there are three ways to drive the browser:
Option 2) doesn't is not as powerful or flexible as the other two alternatives but it provides a simple way to test that pages load correctly and to measure their performance.
The GotoURL methods returns immediate without waiting for the page to load. Normally, you would want to wait for the page to load so that you could look at the traffic that it generated or the performance timings gathered by HttpWatch. The way to do this is to call the Controller object's Wait methods passing the Plugin object reference and a timeout value in seconds (-1 is used to wait forever):
Loading a Page using HttpWatch |
Copy Code
|
---|---|
myUrl = 'http://www.example.com' plugin.GotoUrl( myUrl ) control.Wait( plugin, -1 ) # don't return until the page loads |
For more information about how the page load is detected please see the documentation for the IsLoadingPage property and the Wait method.
The GotoURL method is somewhat limited and only allows you to load pages. If you require more complex interaction with a web page you may want to consider using the Selenium framework with Ruby.
When you wish to stop recording HTTP traffic call the Plugin object's Stop method:
At the end of your application, or earlier, if appropriate, you should close the browser, by calling the Plugin object's CloseBrowser method: